<?php
global $G_LANG;
require_once(SITE_ROOT.'/includes/Session.php');
require_once(SITE_ROOT.'/includes/error.php');
require_once(SITE_ROOT.'/includes/language/'.$G_LANG.'/definetext.php');
require_once(SITE_ROOT.'/includes/tools/fk_datetime.php');
require_once(SITE_ROOT.'/includes/tools/fk_utils.php');
require_once(SITE_ROOT.'/includes/reservewords.php');
require_once(SITE_ROOT.'/includes/FaceKooElement.php');
require_once(SITE_ROOT."/includes/RecordSet.php");
require_once(SITE_ROOT.'/includes/tools/id.php');
require_once(SITE_ROOT.'/includes/Security.php');
require_once(SITE_ROOT.'/includes/application/SanGuoApplication.php');

class User extends FaceKooElement {

    static public $ranking_exclude_users = array('888','62');

/*
23-游戏成绩 30-我收到的礼物 34-我的投票 22-轻描淡写
17-魔镜 14-大头贴 4-KOO图  16-日志 28-晒柜 9-小动作
36-神舟三国 10-踩我的人 15-留言板 6-好友 18-社区帖子 1-神舟卫星消息
*/

	protected $default_leftlayout = '23,30,34,22';
	protected $default_centerlayout = '17,14,4,16,28,9';
	protected $default_rightlayout = '40,36,10,15,6,18,1';
	protected $default_koo_money = '20';
	

	private $points_friends = 2;
	private $points_invite_accepted = 200;

	public function __construct($id, $name, $default_privacy,$day_max_points) {
		parent::__construct($id, $name, $default_privacy,$day_max_points);
	}

	/**
     * 判断$source_uid和$target_uid的关系链
     *
     * @param unknown_type $source_uid
     * @param unknown_type $target_uid
     * @return unknown
     */
	public function getTwoUsersRelation($source_uid,$target_uid) {
		global $mysqli_read;
		if($source_uid==$target_uid || !is_id_valid($source_uid) || !is_id_valid($target_uid) )
		return false;      // 无法判断

		// 先判断二者是否直接是好友关系
		$sql="select friendid,nickname,mainphoto,username from fk_friends,fk_users b where myid='$source_uid' and friendid='$target_uid' and b.id=friendid limit 1";
		$result1 = $mysqli_read->query($sql);
		if($result1->num_rows==0) {
			// 二者不直接是好友,则再判断是否是二度好友关系
			$sql="SELECT g.myid,nickname,username,mainphoto FROM fk_friends f,fk_friends g,fk_users b WHERE g.myid=f.friendid AND f.myid='$source_uid' AND g.friendid='$target_uid' and b.id=g.myid ORDER BY RAND() LIMIT 1";
			$result = $mysqli_read->query($sql);
			if($result->num_rows==0) {
				return false;      // 大于2度好友关系
			} else {
				$row = $result->fetch_array(MYSQLI_ASSOC);
				return $row['myid'];
			}
		} else {
			return 1;       // 直接好友关系
		}
	}




	/**
	 * 功能:取得某人的一些基本资料
	 * @param:$userid:人员id号
	 * @param:$viewerid:当前查看者的id号，默认为空，以确认查看者和被查看者是否好友关系等
	 * 返回值:个人资料记录
	 * 备注:在此函数中加入了错误处理,即:如果没有userid这个用户,则自动转向一个错误页面	 
	 * 		在此处加入此错误处理是为了方便其他模块不用再都进行类似错误处理了
	*/
	public function getUserDetail($userid) {
		global $mysqli_read;
		static $user_detail=array();

		if( $userid=="" || !is_id_valid($userid) ) {
			set_error("no_such_user: $userid","您试图访问的用户不存在！");
		} else {
			if (isset($user_detail[$userid])) {
				return $user_detail[$userid];
			}
			$sql = "select fk_users.*,year( birthday ) as birthday_year , month( birthday ) as birthday_month, day( birthday ) as birthday_day,(SELECT sum( points ) FROM fk_userpoints_day WHERE user_id = '$userid' AND date(subtime)=curdate() ) AS daypoints from fk_users LEFT JOIN fk_userpoints_day b ON ( fk_users.id = b.user_id ) where id='$userid'";
			$result = $mysqli_read->query($sql);
			if($result->num_rows==0) {
				set_error("no_such_user: $userid","您试图访问的用户不存在！");
			}
			$row = $result->fetch_array(MYSQLI_ASSOC);
			if($row['userislock']=='1') {
				set_error("user_is_locked: $userid","您试图访问的用户已经被锁定！");
			}

			// 注意:$zodiac_array和$horoscope_array均在includes/language/***/definetext.php中进行了预定义
			global $zodiac_array;
			global $horoscope_array;
			$row['zodiac'] = $zodiac_array[$row['zodiac']];
			$row['horoscope'] = $horoscope_array[$row['horoscope']];

			// 判断用户的资料完整度,以显示用户头像右侧的星星
			if($row['birthday']!="" && $row['country']!="" && $row['state']!="" && $row['height']!="" && $row['weight']!="" && $row['build']!="" && $row['school']!="" &&	$row['look']!="" && $row['vocation']!="" && $row['degree']!="") {
				$row["info_integrality"] = "1";
			} else {
				$row["info_integrality"] = "0";
			}

			//计算用户资料完整度
			$userInfoPercent = array("nickname","realname","birthday","country","school","height","weight","build","look","vocation","degree","email","mobile","msn","qq","skype","mainphoto","skin");
			$percent = 0;
			$bind_info_exit = 0;
			foreach ($userInfoPercent as $content){
				if(trim($row[$content]) != "" && $row[$content]!='-1' && $row[$content]!='0000-00-00' ){
				    if( ($content=="mobile" || $content=="msn" || $content=="qq" || $content=="skype") ) {
				        if( !$bind_info_exit ) {
				            $bind_info_exit = 1;
				            $percent++;
				        }
				    } else {
					    $percent++;
					}
				}
			}
		}
		$row["userProfilePercent"] = ceil(($percent / ( count($userInfoPercent) - 3) * 100));		
		$row["level"] = FaceKooElement::getLevelFromPoints($row["points"]);
		$row["level_name"] = get_level_name($row["virtual_career"],$row["level"],$row["sex"]);
		$row["points_to_next_level"] = FaceKooElement::getPointsToNextLevel($row["points"]);
		$user_detail[$userid] = $row;
		return $row;
	}

	/**
	 * @todo:在用户登录成功后,更新一些该用户的某些资料
	 * @param:$userid:登录者的id号
	 * @return :true:成功,false:失败
	*/	
	public function updateAfterLogin($userid,$sessionid,$loginip,$extended=0) {
                global $mysqli_write, $gSession;
		$userid = mysql_escape_string($userid);
		$sessionid = mysql_escape_string($sessionid);
		$loginip = mysql_escape_string($loginip);
		$mysqli_write->query("REPLACE fk_user_sessionid SET userid='$userid',sessionid='$sessionid'");
		$mysqli_write->query("UPDATE fk_users SET lastlogtime=NOW(),lastseen=NOW(),lastlogip='$loginip' WHERE id='$userid'");
                if ($gSession) {
                    $gSession->setUser($sessionid, $userid, $extended);
                }
	}

	public function getLatestUpdateTime($userid,$session_id="") {
	    $userid = mysql_escape_string($userid);
            $session_id = mysql_escape_string($session_id);
            if ($session_id != "") {
                $sql = "SELECT session_last_visit FROM sessions WHERE session='$session_id'";
            } else {
                $sql = "SELECT session_last_visit FROM sessions s, fk_user_sessionid u WHERE u.userid='$userid' AND s.session=u.sessionid";
            }

            global $mysqli_read;
            if (($result = $mysqli_read->query($sql)) && 
                ($row = $result->fetch_array(MYSQLI_ASSOC))) {
                return $row['session_last_visit'];
            } else {
                return 0;
            }
	}

	/**
	 * @todo:判断某用户是否在线
	 * @param:$userid:登录者的id号
	 * @return :1:在线,0:不在线
	*/	
	public function getOnlineStatus($userid,$session_id="") {
		global $G_SESSIONTIMER;
		static $user_online = array();
		if (isset($user_online[$userid])) {
			return $user_online[$userid];
		}
		$latest_update_time = $this->getLatestUpdateTime($userid,$session_id);
		if ($latest_update_time != -1) {
			if( (time() - $latest_update_time) > $G_SESSIONTIMER) {
				$user_online[$userid] = 0;
				return 0;
			} else {
				$user_online[$userid] = 1;
				return 1;
			}
		} else {
			$user_online[$userid] = 0;
			return 0;
		}
	}

	/**
	 * @todo:判断用户的sessionid是否需要更新,需要则更新,不需要则不更新
	 * @param:$userid:登录者的id号
	*/	
	public function setUserSessionid($userid) {
            global $mysqli_read, $gSession;
            $userid = mysql_escape_string($userid);		
            $res = $mysqli_read->query("select sessionid from fk_user_sessionid where userid='$userid'");

            // 查询出错或者没有查到相关记录，则直接返回
            if(!$res || $res->num_rows==0 )
		return ;
            $row = $res->fetch_array(MYSQLI_ASSOC);
            if (session_id()!=$row['sessionid']) {
                global $mysqli_write;
                $mysqli_write->query("update fk_user_sessionid set sessionid='".session_id()."' where userid='$userid'");
                if ($gSession) {
                    $gSession->setUser(session_id(), $userid);
                }
            }
	}
	/**
	 * @todo 判断用户的形象照头像是否存在
	 * @param int $userid 用户的id号
	 * @param string $mainphotoname 形象照图片名称
	 * @param int $size 欲显示的形象照的尺寸
	 * @return string 应该显示的形象照 
	*/
	public function getUserMainphoto($userid,$mainphotoname,$size=60) {
		$userPath = get_user_picture_path($userid);
		if($mainphotoname=="") {
			return "/images/none_".$size.".gif";
		}

		if(file_exists(SITE_ROOT."/user/".$userPath."/".$size."X".$size."/".$mainphotoname)) {
			return "/user/".$userPath."/".$size."X".$size."/".$mainphotoname;
		} else {
			return "/images/none_".$size.".gif";
		}
	}

	/**
	 * @todo 取得最新注册的N个用户
	 * @param int $nums 取得的人数	 
	 * @param int $nicknamelength 人员昵称的截取长度
	*/
	public function getNewRegistuser( $nums ) {
		global $mysqli_read;
		$nums = mysql_escape_string($nums);		
		$result = $mysqli_read->query("SELECT id,nickname,username,mainphoto,sex FROM fk_users WHERE userislock='0' AND regdate > SUBTIME(NOW(), '1 00:00:00') ORDER BY regdate DESC limit $nums");
		while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
			$resArr[] = $row;
		}
		return $resArr;
	}
	/*
	想加我为好友的用户总数
	*/
	public function getFriendRequestNums($myid){
		if( is_id_valid($myid)){
			global $mysqli_read;
			$result=$mysqli_read->query(" select myid from fk_friendrequests,fk_users u where u.userislock='0' and u.id=myid and friendid='$myid' and status=0 and mydelete=0 and frienddelete=0 ");			
			return $result->num_rows;
		}else{
			return 0;
		}
	}
	/*
	我想加为好友的用户的总数
	*/
	public function getMyRequestNums($myid){
		if( is_id_valid($myid)){

			global $mysqli_read;
			$result=$mysqli_read->query(" select friendid from fk_friendrequests where myid='$myid' and status=0 and mydelete=0 and frienddelete=0 ");
			return $result->num_rows;
		}else{
			return 0;
		}
	}
	/*
	我想加为好友的用户对自己请求的回复总数
	*/
	public function getFriendRequestReplyNums($myid){
		if( is_id_valid($myid)){

			global $mysqli_read;
			$result=$mysqli_read->query(" select friendid from fk_friendrequests where myid='$myid' and status<>0 and mydelete=0 and frienddelete=0 ");
			return $result->num_rows;
		}else{
			return 0;
		}
	}

	public function postLogin($username,$userpass) {
		global $mysqli_read,$mysqli_write;
		$userName   = $mysqli_read->real_escape_string($username);
		$passwd     = $mysqli_read->real_escape_string($userpass);

		$sql = "select * from fk_users where username='$userName' and userpass='$passwd' limit 1";
		$result = $mysqli_read->query($sql);
		if($result->num_rows == 1) {
			$row = $result->fetch_array(MYSQLI_ASSOC);
			if ($row['userislock']=='1') {
				return "islock";
			}
			$_SESSION['G_USERID']=$row["id"];
			$_SESSION['G_USERNAME']=$row["username"];
			$_SESSION['G_NICKNAME']=$row["nickname"];
			$_SESSION['G_USERSEX']=$row["sex"];
			$_SESSION['G_USEREMAIL']=$row["email"];
			$_SESSION['G_BBSMANAGER']=$row["ifbbsmanager"];	// 用户是否为论坛总管理员
			$_SESSION['G_INDEXEXPEND'] = $row['indexexpend'];
			$_SESSION['G_FANTI'] = $row['fanti'];
			$_SESSION['G_REFRESHTIME'] = $row['satellite_auto_refresh'];
			// 登录成功后,更新各项需要更新的用户资料
			/*活动页面*/
			if($_SESSION['GUEST_USERID']!=""){
				$app=FaceKoo::getElementObject(11);
				$searchgameapp=FaceKoo::getElementObject(38);
				$guest_uid=$_SESSION['GUEST_USERID'];
				$faceresult=$searchgameapp->getTempResult($guest_uid);
				if($faceresult!=false && is_array($faceresult)){
					$faceresult['usersex']=$_SESSION['G_USERSEX'];
					if($_SESSION['joingame']=="1"){
						$app->saveResult($_SESSION['G_USERID'],$faceresult,"1");
					}else{
						$app->saveResult($_SESSION['G_USERID'],$faceresult);
					}
	
					$tempphotoname=$faceresult['userphoto'];
	            	$tempphotoname1=$faceresult['basephotoname'];            	
					if(file_exists($tempphotoname)){
						@unlink($tempphotoname);	
					}				
					if(file_exists($tempphotoname1)){
						@unlink($tempphotoname1);
					}				
					$searchgameapp->delTempResult($guest_uid);
				}
				$_SESSION['GUEST_USERID']="";
				$_SESSION['joingame']="";
			}
			/*wii的保存*/
			if($_SESSION['GUEST_WIIUSERID']!=""){
				$wiiapp=FaceKoo::getElementObject(41);
				$wiiapp->savefromTempresult($_SESSION['GUEST_WIIUSERID'],$_SESSION['G_USERID']);
				$_SESSION['GUEST_WIIUSERID']="";				
			}
		
			$sessionid = session_id();
			$userip = get_real_ip();
            $extended = ($_POST['saves']=="1");
			$this->updateAfterLogin($row["id"],$sessionid,$userip, $extended);
			$result->free();

			if($extended) {
				setcookie(session_name(), session_id(), time()+30*24*60*60, "/", ".facekoo.com");
			} else {
				setcookie(session_name(), session_id(), 0, "/", ".facekoo.com");
			}

			$pre_url = $_POST['preurl'];
			if($pre_url!="") {
				return $pre_url;
			} else {

				return "/modules/controlcenter.php";
			}
		} else {
			return "nothisuser";
		}
	}

	public function postRegist($invitecode, $userName, $passwd, $email, $nickname,$country,$state,$city,$tel,$qq,$msn,$sex,$birthday,$pubbir,$ifaccept,$comeFrom) {
            
		global $mysqli_read,$mysqli_write,$_LANG;
		/*保存用户以前session*/
		if($_SESSION['GUEST_USERID']!="" || $_SESSION['GUEST_WIIUSERID']!=""){
			$sessionback=$_SESSION;	
		}
        $this->postLogout();
		$invitecode       = $mysqli_read->real_escape_string($invitecode);
		$userName       = $mysqli_read->real_escape_string(trim($userName));
		$passwd         = $mysqli_read->real_escape_string($passwd);
		$email          = $mysqli_read->real_escape_string($email);
		$nickname_arr   = Security::checkRejectWords($mysqli_read->real_escape_string(trim($nickname)),false);
		$nickname       = $nickname_arr[0];		
		$country        = $mysqli_read->real_escape_string($country);
		$state          = $mysqli_read->real_escape_string($state);
		$city           = $mysqli_read->real_escape_string($city);
		$tel            = $mysqli_read->real_escape_string($tel);
		$qq		        = $mysqli_read->real_escape_string($qq);
		$msn        	= $mysqli_read->real_escape_string($msn);
		$sex            = $mysqli_read->real_escape_string($sex);
		$birthday       = $mysqli_read->real_escape_string($birthday);
		$pubbir       	= $mysqli_read->real_escape_string($pubbir);
		$ifaccept       = $mysqli_read->real_escape_string($ifaccept);
		$comeFrom       = $mysqli_read->real_escape_string($comeFrom);

		$sourceid = "";
		$sql ="select id from fk_users where username='".$userName."' limit 1";
		$result = $mysqli_read->query($sql);
		$num_rows = $result->num_rows;
		$result->free();
		if ($num_rows>0){

			// 说明在填写注册资料过程中已经有人占用了已经验证过的用户名
			
			/*如果用户注册失败 则保存session*/
			if($sessionback!=""){
				$_SESSION=$sessionback;
			}
			/**/
			return $_LANG['regist_fail_usernameexist'];
			exit;
		} else {
			$errno=0;
			$userip = get_real_ip();	// 当前注册者的IP地址
			if($invitecode!="") {
				$result = $mysqli_read->query("select id from fk_users where id='$invitecode'");
				if($result && $row = $result->fetch_array(MYSQLI_ASSOC)) {
					$sourceid = $row['id'];
				} else {

					// 下面这部分代码以后可以不用
					$result = $mysqli_read->query("select sourceid from fk_invites where invitecode='$invitecode'");
					if($result && $row = $result->fetch_array(MYSQLI_ASSOC))
					$sourceid = $row['sourceid'];
				}
			}

			// 开始事务
			$mysqli_write->autocommit(false);

			// 先写入资料到注册用户表
			$userId = get_unique_id();
			if($birthday!="--") {
				$sql1="insert into fk_users(id, username, userpass, nickname, regdate, sex, country, state, city, tel,  email, birthday, qq, msn, lastlogtime, lastseen, lastlogip, acceptnews, birthdaydisp,reg_from, leftlayout, centerlayout, rightlayout,koo_money,inviter_id) values ('$userId', '$userName', '$passwd', '$nickname', now(), '$sex', '$country', '$state','$city','$tel','$email','$birthday','$qq','$msn',now(),now(),'$userip','$ifaccept','$pubbir','$comeFrom', '{$this->default_leftlayout}', '{$this->default_centerlayout}', '{$this->default_rightlayout}', '{$this->default_koo_money}','$sourceid')";
			} else {
				$sql1="insert into fk_users(id, username, userpass, nickname, regdate, sex, country, state, city, tel,  email, birthday, qq, msn, lastlogtime, lastseen, lastlogip, acceptnews, birthdaydisp,reg_from, leftlayout, centerlayout, rightlayout,koo_money,inviter_id) values ('$userId', '$userName', '$passwd', '$nickname', now(), now(), '$sex', '$country', '$state','$city','$tel','$email',null,'$qq','$msn',now(),'$userip','$ifaccept','$pubbir','$comeFrom', '{$this->default_leftlayout}', '{$this->default_centerlayout}', '{$this->default_rightlayout}', '{$this->default_koo_money}','$sourceid')";
			}
			$mysqli_write->query($sql1);
			$errno+=$mysqli_write->errno;
            
			if($nickname_arr[1]!=0){
			    Security::updateTextSecurity("5","0",$userId,$nickname_arr[1],"",$userip);
            }
            
			// 自动将他们加为好友关系和神舟关注
			if ( is_id_valid($sourceid) ) {
			    
			    // 如果邀请人开通了三国游戏，则自动给邀请人增加士兵
			    $res = $mysqli_read->query("select user_id from fk_sg_player where user_id='$sourceid'");			    
			    if($res->num_rows==1) {
    			    $res = $mysqli_read->query("SELECT COUNT(id) as cnt FROM fk_users where inviter_id='$sourceid' AND regdate > SUBTIME(NOW(),'1 00:00:00')");
    				$row = $res->fetch_array(MYSQLI_ASSOC);
    				if($res && $row['cnt']<=3) {
    				    $mysqli_write->query("update fk_sg_player set soldier=soldier+10000,charm=charm+10 where user_id='$sourceid'");
				        $errno+=$mysqli_write->errno;
    				}
    				
    				// 自动邀请他加入三国游戏
    				$sanguo_app = FaceKoo::getElementObject(36);    				
    				$sanguo_app->inviteFriend($sourceid,$userId,false);
			    }
			    
				$mysqli_write->query("insert into fk_friends(myid,friendid,subdate) values('$userId','$sourceid',now())");
				$errno+=$mysqli_write->errno;
				$mysqli_write->query("insert into fk_friends(myid,friendid,subdate) values('$sourceid','$userId',now())");
				$errno+=$mysqli_write->errno;
				$mysqli_write->query("insert into fk_myattentions(ofuser,attentionerid,adddate) values('$userId','$sourceid',now())");
				$errno+=$mysqli_write->errno;
				$mysqli_write->query("insert into fk_myattentions(ofuser,attentionerid,adddate) values('$sourceid','$userId',now())");
				$errno+=$mysqli_write->errno;

				$this->addPoints($userId, $this->points_friends);
				$this->addPoints($sourceid, $this->points_friends);
                                if ($sourceId == "538" ||
                                    $sourceId == "EiSHZHOWoPc_dc" ||
                                    $sourceId == "NUh2Q4yAgLA_94" ||
                                    $sourceId == "171" ||
                                    $sourceId == "FFSAFhHblaY_68" ||
                                    $sourceId == "aEfnReCA-qA_ae" ||
                                    $sourceId == "KUhDU-lxQuA_ac" ||
                                    $sourceId == "E4SGCkMm6T4_10" ||
                                    $sourceId == "lUgpTtKlBCA_35" ||
                                    $sourceId == "554") {
                                    $this->addPoints($sourceid, 2, "popularity");
                                } else {
                                    $this->addPoints($sourceid, $this->points_invite_accepted, "popularity");
                                }

				// 给注册者加入一条小动作
				$valuedesc = $userId."\001".$nickname;
				$sql="INSERT INTO fk_useraction_2 (id,source_uid, valuedesc, whatdesc, elementid, privacy, date) VALUES ('".get_unique_id()."','$sourceid', '$valuedesc', '19', '5', 3, CURDATE())";
				$mysqli_write->query($sql);
				$errno+=$mysqli_write->errno;

				$sql ="INSERT INTO fk_useraction_2 (id,source_uid, elementid,target_uid, notify_target, date) VALUES ('".get_unique_id()."','$sourceid', '6','$userId', 1, CURDATE())";
				$mysqli_write->query($sql);
				$errno+=$mysqli_write->errno;
				$sql ="INSERT INTO fk_useraction_2 (id,source_uid, elementid,target_uid, notify_target, date) VALUES ('".get_unique_id()."','$userId', '6','$sourceid', 1, CURDATE())";
				$mysqli_write->query($sql);
				$errno+=$mysqli_write->errno;
			} else {
				$mysqli_write->query("insert into fk_friends(myid,friendid,subdate) values('$userId','3',now())");
				$errno+=$mysqli_write->errno;
				$mysqli_write->query("insert into fk_friends(myid,friendid,subdate) values('3','$userId',now())");
				$errno+=$mysqli_write->errno;
				$mysqli_write->query("insert into fk_myattentions(ofuser,attentionerid,adddate) values('$userId','3',now())");
				$errno+=$mysqli_write->errno;
				$mysqli_write->query("insert into fk_myattentions(ofuser,attentionerid,adddate) values('3','$userId',now())");
				$errno+=$mysqli_write->errno;

				$mysqli_write->query("insert into fk_friends(myid,friendid,subdate) values('$userId','607',now())");
				$errno+=$mysqli_write->errno;
				$mysqli_write->query("insert into fk_friends(myid,friendid,subdate) values('607','$userId',now())");
				$errno+=$mysqli_write->errno;
				$mysqli_write->query("insert into fk_myattentions(ofuser,attentionerid,adddate) values('$userId','607',now())");
				$errno+=$mysqli_write->errno;
				$mysqli_write->query("insert into fk_myattentions(ofuser,attentionerid,adddate) values('607','$userId',now())");
				$errno+=$mysqli_write->errno;
			}

			// 为用户建立一个自定义相册
			$sql2 = "insert into fk_album(id,albumid,ofuser,albumname,albumdesc,ifchecked) values ('".get_unique_id()."','1','$userId','我的第一个相册','我的第一个相册',1)";
			$mysqli_write->query($sql2);
			$errno+=$mysqli_write->errno;

			// 建立该用户所要用到的文件夹
			$userPath = get_user_picture_path($userId);
			chdir(SITE_ROOT."/user/");
			mkdir("$userPath", 0755, true);
			mkdir("$userPath/base", 0755);
			mkdir("$userPath/pic", 0755);
			mkdir("$userPath/temp", 0755);
			mkdir("$userPath/120X120", 0755);
			mkdir("$userPath/300X300", 0755);
			mkdir("$userPath/560X0", 0755);
			mkdir("$userPath/60X60", 0755);
			mkdir("$userPath/fir", 0755);
			mkdir("$userPath/wii", 0755);
			// 在所有执行过程中都没有错误,则提交事务,否则回滚事务
			if($errno === 0) {
				$mysqli_write->commit();
				// 记录注册者的session信息
				session_start();
				$sessionid = session_id();
				$this->updateAfterLogin($userId,$sessionid,$userip);
				$_SESSION['G_USERID']=$userId;
				$_SESSION['G_USERSEX']=$sex;
				$_SESSION['G_USERNAME']=$userName;
				$_SESSION['G_NICKNAME']=$nickname;
				$_SESSION['G_REFRESHTIME']="0";
				$_SESSION['G_FIRSTCOMEHERE'] = '1';
				$mysqli_write->autocommit(true);
				
				/*活动页面*/
				if($sessionback!="" && $sessionback['GUEST_USERID']!=""){
					$app=FaceKoo::getElementObject(11);
					$searchgameapp=FaceKoo::getElementObject(38);
					$guest_uid=$sessionback['GUEST_USERID'];
					$faceresult=$searchgameapp->getTempResult($guest_uid);
					$faceresult['usersex']=$_SESSION['G_USERSEX'];
					if($sessionback['joingame']=="1"){
						$app->saveResult($_SESSION['G_USERID'],$faceresult,"1");
					}else{
						$app->saveResult($_SESSION['G_USERID'],$faceresult);
					}
					$tempphotoname=$faceresult['userphoto'];
	            	$tempphotoname1=$faceresult['basephotoname'];            	
					if(file_exists($tempphotoname)){
						@unlink($tempphotoname);	
					}				
					if(file_exists($tempphotoname1)){
						@unlink($tempphotoname1);
					}
					$searchgameapp->delTempResult($guest_uid);		
					$faceresult="";
				}
				
				if($sessionback!="" && $sessionback['GUEST_WIIUSERID']!=""){
					$wiiapp=FaceKoo::getElementObject(41);
					$guest_uid=$sessionback['GUEST_WIIUSERID'];
					$wiiapp->savefromTempresult($guest_uid,$_SESSION['G_USERID']);
				}				
				return '1';
				exit;
			} else {
				$mysqli_read->rollback();
				$mysqli_write->autocommit(true);
				/*保存用户session*/
				if($sessionback!=""){
					$_SESSION=$sessionback;
				}
				/**/
				return $_LANG['regist_fail_othererro'];
				exit;
			}
		}
	}

	public function postLogout() {
        global $mysqli_write, $gSession;
		$mysqli_write->query("update fk_user_sessionid set sessionid='0'  where userid='".$_SESSION['G_USERID']."'");
		session_unset();
		session_destroy();
                // PHP < 5.3 bug, have to call session init again after 
                // session_destroy.
                // http://bugs.php.net/bug.php?id=32330
                if ($gSession)
                    $gSession->init();
		setcookie(session_name(), '', 0, '/', '.facekoo.com');
		$_SESSION['G_USERID']="";
	}

	public function postLeaveEmail($email,$flag) {
		if (trim($email) == "" || !is_numeric($flag) ) {
			return $_LANG['requestdataerr'];
			exit;
		}
		global $mysqli_write;
		global $mysqli_read;
		$email = $mysqli_read->real_escape_string($email);
		$flag = $mysqli_read->real_escape_string($flag);

		// 检查该邮箱是否已经被提交过了,大于0表示被提交过了
		$sql ="select id from fk_emailleaved where email='$email' limit 1";
		$result = $mysqli_read->query($sql);
		$num_rows = $result->num_rows;
		$result->free();
		if ($num_rows>0){
			return $num_rows;
		} else {

			$sql = "insert into fk_emailleaved(id,email,subtime,flag) values ('".get_unique_id()."','$email',now(),$flag)";
			$mysqli_write->query($sql);

			if($mysqli_write->errno == 0) {
				return 0;
			} else  {

				// -1表示数据操作错误
				return -1;
			}
		}
	}
	public function checkUsernameRepeat($username) {
		global $mysqli_read,$reg_username_array;
		$name = strtolower($mysqli_read->real_escape_string($username));
		// 判断注册用的用户名是否是保留关键字
		$security = Security::checkRejectWords($username);
		if (in_array($name, $reg_username_array)||$security[1]>0) {
			/*old  return "@-1@".$name;*/
			/*2008.5.9[*lz*] start*/
			return "{autoRegistResult:-1,autoRegistName:'$name'}";
			/*2008.5.9[*lz*] end*/
			exit;
		}

		$sql = "select id from fk_users where username='$name' limit 1";
		$result = $mysqli_read->query($sql);
		/*old return "@".$result->num_rows;*/
		/*2008.5.9[*lz*] start*/
		return "{autoRegistResult:'$result->num_rows'}";
		/*2008.5.9[*lz*] end*/
	}
	public function checkEmailRepeat($email) {
		global $mysqli_read;
		$email = $mysqli_read->real_escape_string($email);
		$sql = "select id from fk_users where email='$email' limit 1";
		$result = $mysqli_read->query($sql);
		return "@".$result->num_rows;
		//        /*old return "@".$result->num_rows;*/
		//		/*2008.5.9[*lz*] start*/
		//		return "{autoRegistResult:'$result->num_rows'}";
		//		/*2008.5.9[*lz*] end*/
	}

	public function checkNicknameValide($nickname) {
		global $mysqli_read,$reg_nickname_array;
		$nickname = strtolower($mysqli_read->real_escape_string($nickname));
		// 判断注册用的昵称是否是保留关键字
		if (in_array(str_replace(" ","",$nickname), $reg_nickname_array)) {
			/*old  return "@-1@".$nickname;*/
			/*2008.5.9[*lz*] start*/
			return "{autoRegistNickResult:-1,autoRegistNickName:'$nickname'}";
			/*2008.5.9[*lz*] end*/
			exit;
		}else {
			return "{autoRegistNickResult:0}";
		}}
		public function checkTelRepeat($tel) {
			global $mysqli_read;
			$tel = $mysqli_read->real_escape_string($tel);
			$sql = "select id from fk_users where tel='$tel' limit 1";
			$result = $mysqli_read->query($sql);
			return "@".$result->num_rows;
		}
		public function checkMsnRepeat($msn) {
			global $mysqli_read;
			$msn = $mysqli_read->real_escape_string($msn);
			$sql = "select id from fk_users where msn='$msn' limit 1";
			$result = $mysqli_read->query($sql);
			return "@".$result->num_rows;
		}
		public function checkQqRepeat($qq) {
			global $mysqli_read;
			$qq = $mysqli_read->real_escape_string($qq);
			$sql = "select id from fk_users where qq='$qq' limit 1";
			$result = $mysqli_read->query($sql);
			return "@".$result->num_rows;
		}

		/**
     * 用户更新自己的space空间的布局
     *
     */
		public function updateSpaceLayout($userid,$left,$center,$right) {
			global $mysqli_write;
			if($userid==="" || !is_id_valid($userid)){
				return false;
			}

			$left = $mysqli_write->real_escape_string($left);
			$center = $mysqli_write->real_escape_string($center);
			$right = $mysqli_write->real_escape_string($right);


			$default_array = array_merge( split(",",$this->default_leftlayout), split(",",$this->default_centerlayout), split(",",$this->default_rightlayout) );
			$update_array = array_merge( split(",",$left), split(",",$center), split(",",$right) );
			if(count($update_array)!=count($default_array)) {
				return false;
			}
			$update_value_array = array_count_values($update_array);
			foreach($update_value_array as $ele) {
				if ($ele!=1)
				return false;
			}

			$sql = "update fk_users set leftlayout='$left',centerlayout='$center',rightlayout='$right' where id='$userid'";
			$result = $mysqli_write->query($sql);
			if($mysqli_write->errno==0)
			return true;
			else
			return false;
		}

		function getIdFromUsername($username) {
			global $mysqli_read;
			$username = mysql_escape_string($username);
			$result = $mysqli_read->query("select id from fk_users where username='$username'");
			if ($row=$result->fetch_array(MYSQLI_ASSOC)){
				$result->free();
				return $row['id'];
			}
			$result->free();
			return 0;
		}

		/**
     * 更新用户的心情
     *
     */
		public function updateUserMood($userid,$mood) {
			global $mysqli_read,$mysqli_write;
			$userid = mysql_escape_string($userid);
			$mood = mysql_escape_string($mood);
			$sql="update fk_users set mood='$mood' where id='$userid'";
			$mysqli_write->query($sql);
			$res=$mysqli_read->query( "select personalsign from fk_users where id='$userid'" );
			$row = $res->fetch_array(MYSQLI_ASSOC);
			if(trim($row['personalsign']) != ""){
				$insertId = get_unique_id();
				$mysqli_write->query("INSERT INTO fk_user_status VALUES('$insertId','$userid','$mood','{$row['personalsign']}',now())");
			}	
			if($mysqli_write->errno) {
				return true;
			} else {
				return false;
			}
		}
		/**
     * 读取$userid的最近要过生日的好友
     *
     * @param $userid:用户ID号
     * @param $days:最近多少天过生日
     */
		public function getRecentBirthdayFriend($userid,$days) {
			global $mysqli_read;
			if ($userid == '607' || $userid == '3')
			return;
			$now = time();
			//$days = 2;
			for($i=0;$i<$days;$i++) {
				$now_date = getdate($now + $i*60*60*24);
				$date_array[] = $now_date;
				if(function_exists("solar_to_lunar")) {
					$cndate_array[] = solar_to_lunar($now_date['year'],$now_date['mon'],$now_date['mday'] );
				}
			}
			$mysqli_read->query("SET @days := 0");
			if (count($date_array) > 0) {
				// gregorian calendar birthday
				$sql = "SELECT id,mainphoto,nickname,username,birthday,mood,DAY(birthday) AS day,MONTH(birthday) AS month,if_leap,birthdayflag,cn_birthday_month,cn_birthday_day,0 AS lunar,@days AS subtime FROM fk_users u JOIN fk_friends f ON (u.id=f.friendid AND u.userislock='0') WHERE f.myid='$userid' AND (";
				for($j=0;$j<count($date_array);$j++) {
					if ($j!=0) $sql .= " OR ";
					$sql .= "IF(MONTH(birthday)=".$date_array[$j]['mon']." AND DAY(birthday)=".$date_array[$j]['mday']." AND birthdayflag IN (1,3),(@days:=$j) OR 1,0)";
				}
				$sql .= ")";
			}
			if (count($cndate_array) > 0) {
				// chinese calendar birthday
				$sql .= " UNION ALL SELECT id,mainphoto,nickname,username,birthday,mood,DAY(birthday) AS day,MONTH(birthday) AS month,if_leap,birthdayflag,cn_birthday_month,cn_birthday_day,1 AS lunar,@days AS subtime FROM fk_users u JOIN fk_friends f ON (u.id=f.friendid AND u.userislock='0') WHERE f.myid='$userid' AND (";
				for($j=0;$j<count($date_array);$j++) {
					if ($j!=0) $sql .= " OR ";
					$sql .= "IF(cn_birthday_month=".$cndate_array[$j]['month']." AND cn_birthday_day=".$cndate_array[$j]['day']." AND birthdayflag IN (2,3),(@days:=$j) OR 1,0)";
				}
				$sql .= ")";
			}
			$sql .= " ORDER BY subtime";
			$result=$mysqli_read->query($sql);			
			$ret = new RecordSet;
			while ($row=$result->fetch_array(MYSQLI_ASSOC)){
				$ret->recordArray[] = $row;
			}
			$result->free();
			return $ret;
		}
		/**
     * 得到最新注册的用户列表
     *
     * @param int $userid 登录用户id，新人列表里不包括本人
     * @param int $nums 读取新人的个数
     */
		public function getNewRegisters($userid,$nums){
			global $mysqli_read;
			$userid = mysql_escape_string($userid);
			$nums = mysql_escape_string($nums);
			//if($userid>0){
			//    $sql_select = "SELECT id,nickname,mainphoto FROM fk_users where id <> '$userid' and userislock='0' and (mainphoto<>'' or mainphoto is not null) ORDER BY id desc LIMIT $nums ";
			//}else{
			$sql_select = "SELECT id,nickname,username,mainphoto,sex FROM fk_users where userislock='0' and mainphoto<>'' and mainphoto is not null and mainphotocheck='1' ORDER BY regdate desc LIMIT $nums ";
			//}
			$result = $mysqli_read->query($sql_select);
			while($row = $result->fetch_array())
			{
				$resultArr[]=$row;
			}
			$result->free();
			return $resultArr;
		}

		public function setIndexExpend($userid,$moduleid,$flag) {
			global $mysqli_read,$mysqli_write;
			$value=0;
            $userid = mysql_escape_string($userid);
			$moduleid = mysql_escape_string($moduleid);
			$flag = mysql_escape_string($flag);
			
			// 查看有无该用户的配置记录，有则更新，没有则插入
			$res = $mysqli_read->query("select indexexpend from fk_users where id='$userid'");
			if (!$res) {
				return false;
			} else {
				$row = $res->fetch_array();
				$value = $row['indexexpend'];
				if ($flag=="1")
				$value |=(1<<intval($moduleid));
				else
				$value &=~(1<<intval($moduleid));
				$sql = "update fk_users set indexexpend='$value' where id='$userid'";
				$mysqli_write->query($sql);
			}
			if($mysqli_write->errno==0) {
				return $value;
			} else {
				return false;
			}
		}
		public function updateFanti($userid, $fanti) {
			global $mysqli_write;
			$userid = mysql_escape_string($userid);
			$fanti = mysql_escape_string($fanti);
			$fanti = ($fanti != '0') ? 1 : 0;
			$mysqli_write->query("UPDATE fk_users SET fanti='$fanti' WHERE id='$userid'");
		}
		public function getBirthdayInfo($uid) {
			global $mysqli_read;
			$uid = mysql_escape_string($uid);
						
			$sql = "SELECT MONTH(birthday) AS bday_month, DAY(birthday) AS bday_day, cn_birthday_month, cn_birthday_day, birthdayflag FROM fk_users WHERE id='$uid'";
			$result = $mysqli_read->query($sql);
			if ($row=$result->fetch_array(MYSQLI_ASSOC)) {
				$bday_month = $row['bday_month'];
				$bday_day = $row['bday_day'];
				$cn_bday_month = $row['cn_birthday_month'];
				$cn_bday_day = $row['cn_birthday_day'];
				$celebrate_gbday = ($row['birthdayflag']=='1' || $row['birthdayflag']=='3');
				$celebrate_cbday = ($row['birthdayflag']=='2' || $row['birthdayflag']=='3');
			}
			return array($bday_month, $bday_day, $celebrate_gbday,
			$cn_bday_month, $cn_bday_day, $celebrate_cbday);
		}
		/**
		 * 获取个人用户生日提醒
		 *
		 * @param unknown_type $userId
		 */
		public function getUserBirthdayReminder($userid){			
			global $mysqli_read;
			if ($userid == '607' || $userid == '3')
			return;
			$now = time();			
			$days = '7';
			for($i=-1;$i<$days;$i++) {
				$now_date = getdate($now + $i*60*60*24);
				$date_array[] = $now_date;
				if(function_exists("solar_to_lunar")) {
					$cndate_array[] = solar_to_lunar($now_date['year'],$now_date['mon'],$now_date['mday'] );
				}
			}
			$mysqli_read->query("SET @days := 0");
			if (count($date_array) > 0) {
				// gregorian calendar birthday
				$sql = "SELECT DAY(birthday) AS day,MONTH(birthday) AS month,if_leap,birthdayflag,cn_birthday_month,cn_birthday_day,0 AS lunar,@days AS subtime FROM fk_users u  WHERE u.id='$userid' AND (";
				for($j=0;$j<count($date_array);$j++) {
					if ($j!=0) $sql .= " OR ";
					$sql .= "IF(MONTH(birthday)=".$date_array[$j]['mon']." AND DAY(birthday)=".$date_array[$j]['mday']." AND birthdayflag IN (1,3),(@days:=$j) OR 1,0)";
				}
				$sql .= ")";
			}
			if (count($cndate_array) > 0) {
				// chinese calendar birthday
				$sql .= " UNION ALL SELECT DAY(birthday) AS day,MONTH(birthday) AS month,if_leap,birthdayflag,cn_birthday_month,cn_birthday_day,1 AS lunar,@days AS subtime FROM fk_users u  WHERE u.id='$userid' AND (";
				for($j=0;$j<count($date_array);$j++) {
					if ($j!=0) $sql .= " OR ";
					$sql .= "IF(cn_birthday_month=".$cndate_array[$j]['month']." AND cn_birthday_day=".$cndate_array[$j]['day']." AND birthdayflag IN (2,3),(@days:=$j) OR 1,0)";
				}
				$sql .= ")";
			}
			$sql .= " ORDER BY subtime";			
			$result=$mysqli_read->query($sql);
			$ret = new RecordSet;
			while ($row=$result->fetch_array(MYSQLI_ASSOC)){
				$ret->recordArray[] = $row;
			}
			$result->free();			
			return $ret->recordArray;
		}

		public function ifUseMagicMirror($uid) {
			global $mysqli_read;
			$uid = mysql_escape_string($uid);
			$sql = "select * from fk_useraction_2 where (elementid='11' or elementid='14') and source_uid='$uid' and whatdesc='0'";
			$result = $mysqli_read->query($sql);
			if($result && $result->num_rows>0) {
				return true;
			} else {
				return false;
			}
		}
		public function ifModifyProfile($uid) {
			global $mysqli_read;
			$uid = mysql_escape_string($uid);
			$sql = "select * from fk_useraction_2 where elementid='5' and source_uid='$uid'";
			$result = $mysqli_read->query($sql);
			if($result && $result->num_rows>0) {
				return true;
			} else {
				return false;
			}
		}
		
		/**
		 * 更新用户工资
		 * @param 用户ID $userid
		 */
		
		public function updateUserSalary($userid) {		    
		    $userid = mysql_escape_string($userid);
		    global $issue_salary_day, $mysqli_read,$mysqli_write,$level_to_salary,$level_default_name;
		    $day = "".date("d")."";
		    if ( $key = array_search($day,$issue_salary_day)===false ) {                
		      return;     // 不是发工资的日子
		    }
		    
		    $res = $mysqli_read->query("select points,virtual_career,sex from fk_users where id='$userid'");
		    if(!$res) {
		        error_log($mysqli_read->error);
		        return;
		    }
		    $row = $res->fetch_array();
		    $user_level = FaceKooElement::getLevelFromPoints($row["points"]);
		    $user_level_name = get_level_name($row["virtual_career"],$user_level,$row["sex"]);
		    if ( $user_level_name == $level_default_name)
		      return;             // 无业游民不发工资
		    
		    $sql = "SELECT * FROM `fk_user_salary` WHERE user_id = '$userid' AND SUBTIME(NOW(), '3 00:00:00') <= subtime AND salary_flag<>'2' AND salary_flag<>'3'";
		    $res = $mysqli_read->query($sql);
		    
		    if(!$res) {
		      error_log("updateUserSalary failed: $sql  error is: ".$mysqli_read->error);
		      return;
		    }
		    
		    if($res->num_rows>0)
		      return;     // 有本期工资的记录了,则不再进行任何处理
		    
		    $salary_flag = $user_level>7 ? 1 : 0;
		    $mysqli_write->query("insert into fk_user_salary (user_id,koo_money,ifdraw,salary_flag) values ('$userid','".$level_to_salary[$user_level]."','0','$salary_flag')");
		    if($mysqli_write->errno!=0)
		    	error_log($mysqli_write->error);
		}
		
		/**
		 * 读取用户待领工资
		 *
		 * @param unknown_type $userid
		 * @return 0:没有待领工资  N:待领工资数额
		 */
		
		public function getSalaryForDraw($userid) {
		   $userid = mysql_escape_string($userid);
		   global $mysqli_read;
		   $res = $mysqli_read->query("select * from fk_user_salary where user_id='$userid' and ifdraw='0'");
		   if(!$res || $res->num_rows==0)
		      return 0;
		   $row = $res->fetch_array(MYSQLI_ASSOC);
		   return $row['koo_money'];
		}
		
		public function getSalaryStatistic($userid) {
		    $userid = mysql_escape_string($userid);
		    global $mysqli_read;
		    $res = $mysqli_read->query("select * from
    		    (select sum(koo_money) as waitdraw from fk_user_salary where user_id='$userid' and ifdraw='0' AND salary_flag<>'2' AND salary_flag<>'3') tbl1,
                (select sum(koo_money) as drawed from fk_user_salary where user_id='$userid' and ifdraw='1') tbl2,
                (select sum(koo_money) as lostdraw from fk_user_salary where user_id='$userid' and ifdraw='2') tbl3,
                (select sum(koo_money) as addtion_salary from fk_user_salary where user_id='$userid' and ifdraw='0' AND salary_flag<>'0' AND salary_flag<>'1') tbl4");
		    if(!$res)
		      return ;
		    $row = $res->fetch_array(MYSQLI_ASSOC);
		    return $row;
		}
		
		public function getUserPointsAndLevel($userid) {
		    $userid = mysql_escape_string($userid);
		    global $mysqli_read;		    
		    $res = $mysqli_read->query("SELECT a.points,a.virtual_career,a.sex, a.koo_money, (select sum(points) from fk_userpoints_day where user_id='$userid' AND date(subtime)=curdate() )  AS daypoints FROM fk_users a WHERE id = '$userid'");
		    $row = $res->fetch_array(MYSQLI_ASSOC);
		    $row["level"] = FaceKooElement::getLevelFromPoints($row["points"]);
		    $row["level_name"] = get_level_name($row["virtual_career"],$row["level"],$row["sex"]);
		    $row["points_to_next_level"] = FaceKooElement::getPointsToNextLevel($row["points"]);
		    return $row;
		}

		function getAdMsg(){
			global $mysqli_write;
			$sql="select count(*) as _cnt from fk_today_recommend where ifpublish='1'";
			$res=$mysqli_write->query($sql);
			$row=$res->fetch_array(MYSQLI_ASSOC);
			$total=$row['_cnt'];
			if($total==0){
				return false;	
			}
			$offset=rand(0,$total-1);
			$sql="select id,shortcut,content from fk_today_recommend where ifpublish='1' limit $offset,1";
			$rk=$mysqli_write->query($sql);
			if($rk->num_rows==0){
				return false;
			}
			$r=$rk->fetch_array();
			$admsg['admsg']=$r['content'];
			$admsg['adpic']="/contentmanager/".$r['shortcut'];
			$admsg['admsgid']=$r['id'];
			return $admsg;
		}

        /**
		 *@param $indexFlash 首页flash 
		 * */
        public function getTopUsers($what='',$indexFlash=false) {
              global $mysqli_read;
              if (!empty($what))
                     $what = "_".$what;
              if($indexFlash)
              	$sql = "SELECT * FROM `fk_top_user` WHERE 1 ORDER BY points DESC LIMIT 25";
              else 
              	$sql = "SELECT id AS userid, nickname, username, mainphoto, sex FROM fk_users WHERE id NOT IN ('".implode("','",self::$ranking_exclude_users)."') AND userislock='0' ORDER BY points$what DESC LIMIT 100";
              $result = $mysqli_read->query($sql);
              $ret = new RecordSet;
              while ($row=$result->fetch_array(MYSQLI_ASSOC)){
                      $ret->recordArray[] = $row;
              }
              $result->free();
              return $ret;
      }
      public function getUserSpaceTip($userid){
	  		global $mysqli_read,$mysqli_wirte;
	  		$sql="select b.id,b.subtime,b.msg from fk_users a,fk_newreport b  where a.id='$userid' and a.closetiptime < b.subtime  and b.ifpublish='1' order by b.subtime desc limit 1";  		
	  		$rs=$mysqli_read->query($sql);
	  		if($rs->num_rows == 1){	 
	  			$newrow=$rs->fetch_array(MYSQLI_ASSOC); 		
      			return $newrow;
	  		}else{
      			return false;
	  		}
      }
      public function closeTips($userid,$id){
	  		global $mysqli_write,$mysqli_read;
	  		$sql="select subtime from fk_newreport WHERE id='$id' and ifpublish='1' limit 1";
	  		$res=$mysqli_read->query($sql);
	  		if($res->num_rows == 0){
	  			return false;	
	  		}else{
	  			$row=$res->fetch_array(MYSQLI_ASSOC);
	  			$sql="UPDATE fk_users set closetiptime='".$row['subtime']."' where id='$userid'";
	  			$mysqli_write->query($sql);
	  			if($mysqli_write->errno==0){
	  				return true;
	  			}else{
	  				return false;
	  			}
	  		}
      }
}
?>
